﻿using System.Collections.Generic;

namespace PoolKit.Tests
{
    internal static class ResourceCollectionExtensions
    {
        internal static List<TResource> Drain<TResource>(this ResourceCollection<TResource> resourceCollection)
            where TResource : class
        {
            var resourcesTaken = new List<TResource>();

            TResource newResource;

            while (resourceCollection.TryTake(out newResource))
            {
                resourcesTaken.Add(newResource);
            }

            return resourcesTaken;
        }
    }
}